package com.atwisdom.star.core.dao.pojo.functionClass;

import com.alibaba.fastjson.JSONObject;
import com.atwisdom.star.core.dao.pojo.BaseEntity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * 
 * @TableName documents
 */
@TableName(value ="documents",autoResultMap = true)
@Data
@NoArgsConstructor
public class Documents extends BaseEntity {
    /**
     * 标识
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 名称
     */
    @TableField(value = "name")
    private String name;

    /**
     * 编码
     */
    @TableField(value = "code")
    private String code;

    /**
     * 业务分类
     */
    @TableField(value = "category")
    private String category;

    /**
     * 显示文件名
     */
    @TableField(value = "displayFileName")
    private String displayFileName;

    /**
     * 存储文件名
     */
    @TableField(value = "fileName")
    private String fileName;

    /**
     * 文档扩展名
     */
    @TableField(value = "extendName")
    private String extendName;

    /**
     * 文档存储路径
     */
    @TableField(value = "filePath")
    private String filePath;

    /**
     * 说明
     */
    @TableField(value = "comments")
    private String comments;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;


    public Documents(JSONObject jsonObject) {
        Set<String> keys = jsonObject.keySet();
        this.id = keys.contains("id") ? jsonObject.getLong("id") : null;
        this.name = keys.contains("name") ? jsonObject.getString("name") : null;
        this.code = keys.contains("code") ? jsonObject.getString("code") : null;
        this.category = jsonObject.getString("category");
        this.displayFileName = keys.contains("displayFileName") ? jsonObject.getString("displayFileName") : null;
        this.fileName = keys.contains("fileName") ? jsonObject.getString("fileName") : null;
        this.extendName = keys.contains("extendName") ? jsonObject.getString("extendName") : null;
        this.filePath = keys.contains("filePath") ? jsonObject.getString("filePath") : null;
        this.comments = keys.contains("comments") ? jsonObject.getString("comments") : null;
    }

    /**
     * 获取摘要数据列
     *
     * @return 反回查询列
     */
    public static String[] fetchSimpleColumns() {
        List<String> columns = new ArrayList<>();
        columns.add("id");
        columns.add("name");
        columns.add("code");
        columns.add("category");
        columns.add("displayFileName");
        columns.add("fileName");
        columns.add("extendName");
        columns.add("filePath");
        columns.add("comments");
        columns.add("updatedBy");
        columns.add("updateTime");
        columns.add("createdBy");
        columns.add("createTime");
        return columns.toArray(new String[0]);
    }

    public JSONObject fetchJsonObject() {
        JSONObject JsonObject = new JSONObject();
        JsonObject.put("id", this.id);
        JsonObject.put("name", this.name);
        JsonObject.put("code", this.code);
        JsonObject.put("category", this.category);
        JsonObject.put("displayFileName", this.displayFileName);
        JsonObject.put("fileName", this.fileName);
        JsonObject.put("extendName", this.extendName);
        JsonObject.put("filePath", this.filePath);
        JsonObject.put("comments", this.comments);
        JsonObject.put("createdBy", this.createdBy);
        JsonObject.put("createTime", this.createTime);
        JsonObject.put("updatedBy", this.updatedBy);
        JsonObject.put("updateTime", this.updateTime);
        return JsonObject;
    }
}
